const path = require('path')
const fs = require('fs')
const logPath = path.resolve(process.cwd(), 'logs')

module.exports = {
	appenders: {
		out: {
			type: 'stdout',
		},
		menu: {
			type: 'dateFile',
			// filename: mkdirSync(path.resolve(logPath, "man_all"), 'man_all'),
			filename: 'logs/menu.log',
			// pattern: ".yyyy-MM-dd",
			layout: {
				type: "basic",
			},
		},
	},

	categories: {
		default: {
			appenders: ['out'],
			level: 'all',
		},
		menu: {
			appenders: ['menu', 'out'],
			level: 'all',
		},
	},
}

function mkdirSync(dirPath, name) {
	if (typeof dirPath != 'string') {
		return ''
	}
	let dirArr = dirPath.split(path.sep)
	let tmpDir = ''
	for (let i = 0; i < dirArr.length; i++) {
		let dir = dirArr[i]
		if (!dir) {
			tmpDir += path.sep
		}
		tmpDir = path.join(tmpDir, dir)
		if (!fs.existsSync(tmpDir)) {
			fs.mkdirSync(tmpDir)
		}
	}
	return `${dirPath}/${name}.log`
}